<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    request.setAttribute("basePath",request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath());
%>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
    <style>
        h2{
            margin-left: 283px;
        }
        input{
            width: 603px;
            height: 36px;
            margin-left: 23px;
            border: 1px solid #CFCFCF;
        }
        input[type=button]{
            width: 253px;
            height: 36px;
            margin-left: 93px;
            cursor: pointer;
            border: 1px solid #CFCFCF;
        }
        select{
            width: 605px;
            height: 36px;
            border: 1px solid #CFCFCF;
            margin-left: 23px;
        }
        textarea{
            width: 600px;
            height: 200px;
            border: 1px solid #CFCFCF;
            margin-left: 23px;
        }
        #modes{
            width: 608px;
            height: auto;
            margin-left: 93px;
        }
    </style>
    <title></title>
    <script src="${basePath}/js/jquery-1.5.2.min.js"></script>
    <script type="text/javascript">
        var controllerJson = [
			{"path":"/func_register_or_login","des":"APP注册或登录"},
			{"path":"/func_broker_detail_update","des":"投顾完善信息"},
			{"path":"/func_website_register","des":"官网注册"},
			{"path":"/func_account_imgverify","des":"获取图片验证码"},
			{"path":"/func_account_sendsms","des":"发送验证短信"},
            {"path":"/func_broker_register_check","des":"大V注册页面打开校验"},
            {"path":"/func_broker_register","des":"大V注册"},
            {"path":"/func_broker_auth_info_set","des":"大V设置权限信息"},
            {"path":"/func_account_login","des":"登陆"},
            {"path":"/func_account_logout","des":"登出"},
            {"path":"/func_account_change_password","des":"修改密码"},
            {"path":"/func_account_reset_password","des":"重置密码"},
            {"path":"/func_chatroom_onlinenum_by_broker","des":"当前聊天室在线人数"},
            {"path":"/func_preview_his_chat","des":"浏览聊天历史记录"},
            {"path":"/func_export_his_chat","des":"导出聊天历史记录"},
            {"path":"/func_get_chat_topic_list","des":"投顾直播话题列表"},
            {"path":"/func_account_registernum","des":"注册用户总数"},
            {"path":"/func_account_list","des":"用户列表"},
            {"path":"/func_white_list","des":"白名单列表"},
            {"path":"/func_account_detail","des":"用户详细信息"},
            {"path":"/func_fund_income","des":"查询收入"},
            {"path":"/func_fund_list","des":"查询收入列表"},
            {"path":"/func_fund_export","des":"收入导出"},
            //{"path":"/func_chat_comment","des":"实时评发言"},
            //{"path":"/func_broker_private_letter","des":"大V私信发言"},
            //{"path":"/func_chatroom_gag","des":"聊天室禁言/取消"},
            {"path":"/func_user_gag","des":"粉丝禁言/取消"},
            {"path":"/func_user_block","des":"粉丝拉黑/取消"},
            {"path":"/func_reward_num_get","des":"查询当日打赏次数"},
            {"path":"/func_qry_reward","des":"查询打赏金额"},
            {"path":"/func_chatroom_info","des":"聊天室信息查询"},
            {"path":"/func_chatroom_set","des":"聊天室信息设置"},
            {"path":"/func_chatting_topic_set","des":"设置直播话题"},
            {"path":"/func_question_answer_list_by_dav","des":"提问查询"},
            {"path":"/func_question_answer","des":"提问回答"},
            {"path":"/func_question_answer_update","des":"修改提问回复"},
            {"path":"/func_question_del","des":"删除提问"},
            //{"path":"/func_question_public_or_hide","des":"公开/隐藏提问"},
            {"path":"/func_stock_info_qry","des":"股票代码信息查询"},
            {"path":"/func_stock_list","des":"全市场股票代码列表"},
            {"path":"/func_viewpoint_list_by_dav","des":"观点列表"},
            {"path":"/func_viewpoint_detail_list_by_dav","des":"大V观点信息列表"},
            {"path":"/func_self_media_list_by_dav","des":"自媒体列表"},
            {"path":"/func_viewpoint_content","des":"大V查询观点内容"},
            {"path":"/func_broker_viewpoint_save","des":"大V观点信息保存"},
            {"path":"/func_broker_viewpoint_del","des":"大V观点信息删除"},
            {"path":"/func_comment_view_by_broker","des":"查看观点详细内容与评论"},
            {"path":"/func_viewpoint_top","des":"观点置顶"},
            {"path":"/func_broker_viewpoint_clear","des":"大V观点清空(慎用)"},
            {"path":"/func_viewpoint_comment_list","des":"观点评论查询"},
            {"path":"/func_comment_replay_save","des":"大V观点评论回复"},
            {"path":"/func_comment_save","des":"发表评论"},
            {"path":"/func_viewpoint_comment_del","des":"大V观点评论删除"},
            {"path":"/func_history_record_list","des":"历史查询"},
            {"path":"/func_viewpoint_tag_save","des":"大V增加观点标签"},
            {"path":"/func_viewpoint_tag_update","des":"大V修改观点标签"},
            {"path":"/func_viewpoint_tag_sort","des":"大V排序观点标签"},
            {"path":"/func_viewpoint_tag_list","des":"查询大V标签"},
            {"path":"/func_viewpoint_tag_del","des":"删除大V标签"},
            {"path":"/func_favorite_list","des":"获取收藏夹列表信息"},
            {"path":"/func_favorite_detail","des":"收藏详情查看"},
            {"path":"/func_favorite_del","des":"收藏清空删除（待用）"},
            {"path":"/func_favorite_save","des":"收藏新增"},
            {"path":"/func_favorite_update","des":"收藏修改"},
            {"path":"/func_broker_info_qry","des":"获取大V个人信息"},
            {"path":"/func_broker_info_update","des":"修改大V信息"},
            {"path":"/func_broker_notice_save","des":"大V推送消息保存"},
            {"path":"/func_roll_notice_list","des":"获取滚动播报通知"},
            {"path":"/func_news_save","des":"资讯信息保存"},
            {"path":"/func_news_qry","des":"资讯信息查询"},
            {"path":"/func_set_his_chat","des":"记录聊天信息"},
            {"path":"/func_his_chat_del","des":"删除聊天信息"},
            {"path":"/func_question_noread_num","des":"获取未读问题条数"},
            {"path":"/func_viewpoint_replay_detail_list","des":"观点评论引用详细列表"},
            {"path":"/func_get_his_chat","des":"获取聊天历史记录"},
            {"path":"/func_broker_list","des":"大V列表"},
            {"path":"/func_adpage_list","des":"广告页列表"},
            {"path":"/func_adpage_update","des":"广告页修改"},
            {"path":"/func_rolling_msg_list_get","des":"滚动消息获取"},
            {"path":"/func_rolling_msg_save","des":"滚动消息保存"},
            {"path":"/func_rolling_msg_update","des":"滚动消息修改"},
            {"path":"/func_rolling_msg_del","des":"滚动消息删除"},
            {"path":"/func_common_reply_list","des":"常用语列表"},
            {"path":"/func_common_reply_save","des":"常用语保存"},
            {"path":"/func_common_reply_del","des":"常用语删除"},
            {"path":"/func_scheme_color_select","des":"前端主题颜色选择"},
            {"path":"/func_wechat_share_detail_get","des":"获取微信分享详情"},
            {"path":"/func_wechat_share_set","des":"获取微信分享添加"},
            {"path":"/func_wechat_share_update","des":"微信分享更新"},
            {"path":"/func_wechat_share_del","des":"微信分享删除"},
            {"path":"/func_live_broadcast_url_set","des":"前端直播地址设置"},
            {"path":"/func_common_reply_del","des":"常用语删除"},
            {"path":"/func_broker_manager_save","des":"增加管理员"},
            {"path":"/func_broker_manager_del","des":"删除管理员"},
            {"path":"/func_broker_manager_info","des":"查询管理员信息"},
            {"path":"/func_broker_manager_list","des":"查询管理员列表"},
            {"path":"/func_broker_permission_list","des":"权限列表"},
            {"path":"/func_live_broadcast_url_get","des":"聊天室视频直播获取"},
            {"path":"/func_set_invitation_code","des":"设置fans邀请码"},
            {"path":"/func_get_invitation_code","des":"获取fans邀请码"},
            {"path":"/func_home_page_title_set","des":"设置fans网页主标题"},
            {"path":"/func_payment_option_qry","des":"获取打赏、充值额度"},
            {"path":"/func_payment_option_save","des":"设置打赏、充值额度"},
            {"path":"/func_fund_detail_export","des":"大V资金明细导出"},
            {"path":"/func_fund_uf30_recharge_export","des":"UF30充值资金对账导出"},
            {"path":"/func_fund_uf30_consume_export","des":"UF30金币消费对账导出"},
            {"path":"/func_viewpoint_content_convert","des":"观点说内容格式转换"},
            {"path":"/func_history_import_searchengine","des":"搜索引擎数据导入"},
            {"path":"/func_refresh_accesstoken","des":"手动更新accesstoken"},
            {"path":"/func_broker_account_list","des":"运营端大V列表"},
            {"path":"/func_broker_info","des":"运营端大V详细信息"},
            {"path":"/func_broker_change_status","des":"运营端大V更改状态"},
            {"path":"/func_new_message_num","des":"获取讨论区新消息数目"},
            {"path":"/func_clear_message_num","des":"清空讨论区新消息数目"},
            {"path":"/func_mass_message","des":"微信公众号群发消息"},
            {"path":"/func_get_his_message","des":"获取微信群发历史消息"},
            {"path":"/func_add_opinion","des":"大V端系统设置意见反馈"},
            {"path":"/func_plugs_list","des":"组件列表"},
            {"path":"/func_plugs_save","des":"添加组件"},
            {"path":"/func_plugs_update","des":"修改组件"},
            {"path":"/func_plugs_del","des":"删除组件"},
            {"path":"/func_plugstype_save","des":"添加组件分类"},
            {"path":"/func_plugstype_update","des":"修改组件分类"},
            {"path":"/func_plugstype_list","des":"组件分类列表"},
            {"path":"/func_extendapp_build_group","des":"生成分组"},
            {"path":"/func_extendgroup_list","des":"我的分组"},
            {"path":"/func_extendapp_group_update","des":"修改分组中应用信息"},
            {"path":"/func_extendapp_group_del","des":"删除分组中应用信息"},
            {"path":"/func_extendapp_by_group","des":"获取分组中组件列表"},
            /* {"path":"/func_extendapp_setting","des":"组件配置"}, */
            {"path":"/func_extendapp_buyed_list","des":"已购列表"},
            {"path":"/func_extendgroup_save","des":"添加分组"},
            {"path":"/func_extendgroup_update","des":"修改分组"},
            {"path":"/func_extendgroup_del","des":"删除分组"},
            {"path":"/func_extendapp_by_group_fans","des":"获取分组中组件列表"},
            {"path":"/func_extendapp_buy","des":"组件购买"},
            {"path":"/func_extendgroup_build_default","des":"给指定dav生成默认分组（无需登录）"},
            {"path":"/func_guest_token","des":"获取访客token"},
            {"path":"/func_add_opinion","des":"大V端系统设置意见反馈"},
            {"path":"/func_search_engine_status","des":"搜索引擎状态获取"},
            {"path":"/func_fans_fund_list","des":"管理中台粉丝资金列表"},
            {"path":"/func_broker_fund_list","des":"管理中台投顾资金列表"},
            {"path":"/func_fans_consume_list","des":"管理中台粉丝消费列表"},
            {"path":"/func_fans_charge_list","des":"管理中台粉丝充值列表"},
            {"path":"/func_broker_income_list","des":"管理中台投顾收入列表"},
            {"path":"/func_fans_fund_frozen","des":"管理中台粉丝资金冻结"},
            {"path":"/func_broker_fund_frozen","des":"管理中台投顾资金冻结"},
            {"path":"/func_invest_check_list","des":"投顾审核列表"},
            {"path":"/func_invest_check_process","des":"投顾审核流程配置"},
            {"path":"/func_invest_check","des":"投顾审核"},
            {"path":"/func_invest_check_details","des":"获取审核列表投顾详情"},
            {"path":"/func_invest_account_list","des":"获取在职或限制投顾列表"},
            {"path":"/func_operate_invest_list","des":"限制或者激活投顾"},
            {"path":"/func_get_branch_names","des":"获取归属地"},
            {"path":"/func_common_connect_test","des":"测试所有工程是否正常连接"},
            {"path":"/func_get_invest_details","des":"获取投顾详情"},
            {"path":"/func_itn_access_token","des":"获取itn_access_token"},
            {"path":"/func_operate_get_fans","des":"运营端查询粉丝列表"},
            {"path":"/func_operate_fans_gag","des":"运营端粉丝禁言/取消"},
            {"path":"/func_operate_fans_block","des":"运营端粉丝拉黑/取消"},
            {"path":"/func_operator_white_list","des":"加入白名单/取消白名单"},
            {"path":"/func_pach_send_sms","des":"批量发送中奖短信"},
            {"path":"/func_check_verify_code","des":"效验短信验证码"},
            {"path":"/func_get_tenant","des":"获取租户ID"},
            {"path":"/func_get_branch_list","des":"获取归属地列表"},
            {"path":"/func_set_cc_room_status","des":"关闭/开启CCLive聊天室"},
            {"path":"/func_system_get_skin_info","des":"运营管理端系统设置信息获取s"},
            {"path":"/func_viewpoint_public_get","des":"获取租户观点公开配置"},
            {"path":"/func_self_viewpoint_list","des":"获取自媒体观点管理列表"},
            {"path":"/func_user_count","des":"用户数据统计"},
            {"path":"/func_suggestion_list","des":"意见列表"},
            {"path":"/func_self_viewpoint_review","des":"是否开启自媒体观点审核"},
            {"path":"/func_self_viewpoint_review_status","des":"自媒体观点是否通过审核"},
            {"path":"/func_self_viewpoint_by_id","des":"获取单个自媒体观点的详情"},
            {"path":"/func_viewpoint_review_manange","des":"是否开启普通观点审核"},
            {"path":"/func_viewpoint_review_status_manange","des":"获取普通观点审核配置"},
            {"path":"/func_viewpoint_list_manage","des":"获取普通观点管理列表"},
            {"path":"/func_viewpoint_review_by_id_manage","des":"普通观点是否通过审核"},
            {"path":"/func_viewpoint_operate_list_by_tenant","des":"管理中台观点列表页面"},
            {"path":"/func_viewpoint_comment_operate_list_by_tenant","des":"管理中台观点评论列表页面"},
            {"path":"/func_viewpoint_comment_delete","des":"管理中台观点评论批量删除"},
            {"path":"/func_chat_list_by_tenant","des":"获取直播列表"},
            {"path":"/func_chat_content","des":"获取直播言论"},
            {"path":"/func_batch_del_chat_content","des":"批量删除言论"},
            {"path":"/func_chat_content_info_get","des":"获取直播详情"},
            {"path":"/func_broker_logger_qry","des":"查询投顾登录日志信息"},
            {"path":"/func_invest_change_info","des":"公共平台修改投顾信息"}
        ];
        var accesstoken = "";
        var usertoken = "";
        $(function () {
            $("#txtConller").append(new Option("请选择", "", true));
            for (var i = 0; i < controllerJson.length; i++) {
                var option = new Option(controllerJson[i].path+"..."+controllerJson[i].des, controllerJson[i].path);
                $("#txtConller").append(option);
            }

            $("#txtConller").change(function(){
                var path = $(this).val();
                $.ajax({
                    url: "/js/testdata.json",
                    type: "GET",
                    dataType: "json",
                    success: function (data) {
                        for(var p in data){//遍历json对象的每个key/value对,p为key
                            if("/"+p==path){
                            	if(typeof(data[p].user_token) != "undefined"){
	                            	data[p].user_token = accesstoken;
                            	}
                            	if(typeof(data[p].access_token) != "undefined"){
	                            	data[p].access_token = usertoken;
                            	}
                                $("#txtParams").val(format(JSON.stringify(data[p])));
                            }
                        }
                    }
                });
            });
        });

        function btnSubmit() {
            var address = $("#txtUrl").val();
            var controller = $("#txtConller").val();
            var stype = $("#sType").val();
            var params = $("#txtParams").val();
            if (address == "") {
                return false;
            }
            if (controller == "") {
                alert("请求路径不能为空");
                return false;
            }
            if (stype == "") {
                alert("请求行为必填");
                return false;
            }
            if (params == "") {
                params = null;
            }
            if (params != "") {
                params = JSON.parse(params);
            }
            var rURl = address + controller
            $.ajax({
                url: rURl,
                type: stype,
                data: params,
                dataType: "json",
                success: function (data) {
                	if(data.data[0] && data.data[0].user_token){
                		accesstoken = data.data[0].user_token;
                	}
                	if(data.data[0].access_token){
                		usertoken = data.data[0].access_token;
                	}
                    document.getElementById("modes").innerHTML = CurentTime()+"<br>"+JSON.stringify(data,null,"<p>");
                }
            }).fail(
                    function (xhr, textStatus, err) {
                        var msg = "";
                        if (err == "") {
                            msg = "<span style='color:red;'>服务端错误或服务未启动！</span>";
                        }
                        else {
                            msg = "<span style='color:red;'>" + err + "!</span>";
                        }
                        document.getElementById("modes").innerHTML = CurentTime()+msg;
                    });
        }

        function btnSubmit2() {
            var address = $("#txtUrl").val();
            var controller = $("#txtConller").val();
            var stype = $("#sType").val();
            var params = $("#txtParams").val();
            if (address == "") {
                return false;
            }
            if (controller == "") {
                alert("请求路径不能为空");
                return false;
            }
            if (stype == "") {
                alert("请求行为必填");
                return false;
            }
            if (params == "") {
                params = null;
            }
            if (params != "") {
                params = JSON.parse(params);
            }
            var rURl = address + controller
            $.ajax({
                url: rURl,
                type: stype,
                data: params,
                dataType: "jsonp",
                async: false,
                jsonp: "jsonpcallback", //服务端用于接收callback调用的function名的参数
                success: function(data) {
                    document.getElementById("modes").innerHTML = CurentTime()+"<br>"+JSON.stringify(data,null,"<p>");
                },
                error: function(xhr, textStatus, err){
                    var msg = "";
                    if (err == "") {
                        msg = "<span style='color:red;'>服务端错误或服务未启动！</span>";
                    }
                    else {
                        msg = "<span style='color:red;'>" + err + "!</span>";
                    }
                    document.getElementById("modes").innerHTML = CurentTime()+msg;
                }
            });
        }
        function CurentTime(){
            var now = new Date();
            var year = now.getFullYear();       //年
            var month = now.getMonth() + 1;     //月
            var day = now.getDate();            //日
            var hh = now.getHours();            //时
            var mm = now.getMinutes();          //分
            var ss = now.getSeconds();          //分
            var clock = year + "-";
            if(month < 10)
                clock += "0";
            clock += month + "-";
            if(day < 10)
                clock += "0";
            clock += day + " ";
            if(hh < 10)
                clock += "0";
            clock += hh + ":";
            if (mm < 10) clock += '0';
            clock += mm + ":";
            if (ss < 10) clock += '0';
            clock += ss;
            return("["+clock+"]");
        }

        function format(txt,compress/*是否为压缩模式*/){/* 格式化JSON源码(对象转换为JSON文本) */
            var indentChar = '    ';
            if(/^\s*$/.test(txt)){
                alert('数据为空,无法格式化! ');
                return;
            }
            try{var data=eval('('+txt+')');}
            catch(e){
                alert('数据源语法错误,格式化失败! 错误信息: '+e.description,'err');
                return;
            };
            var draw=[],last=false,This=this,line=compress?'':'\n',nodeCount=0,maxDepth=0;

            var notify=function(name,value,isLast,indent/*缩进*/,formObj){
                nodeCount++;/*节点计数*/
                for (var i=0,tab='';i<indent;i++ )tab+=indentChar;/* 缩进HTML */
                tab=compress?'':tab;/*压缩模式忽略缩进*/
                maxDepth=++indent;/*缩进递增并记录*/
                if(value&&value.constructor==Array){/*处理数组*/
                    draw.push(tab+(formObj?('"'+name+'":'):'')+'['+line);/*缩进'[' 然后换行*/
                    for (var i=0;i<value.length;i++)
                        notify(i,value[i],i==value.length-1,indent,false);
                    draw.push(tab+']'+(isLast?line:(','+line)));/*缩进']'换行,若非尾元素则添加逗号*/
                }else   if(value&&typeof value=='object'){/*处理对象*/
                    draw.push(tab+(formObj?('"'+name+'":'):'')+'{'+line);/*缩进'{' 然后换行*/
                    var len=0,i=0;
                    for(var key in value)len++;
                    for(var key in value)notify(key,value[key],++i==len,indent,true);
                    draw.push(tab+'}'+(isLast?line:(','+line)));/*缩进'}'换行,若非尾元素则添加逗号*/
                }else{
                    if(typeof value=='string')value='"'+value+'"';
                    draw.push(tab+(formObj?('"'+name+'":'):'')+value+(isLast?'':',')+line);
                };
            };
            var isLast=true,indent=0;
            notify('',data,isLast,indent,false);
            return draw.join('');
        }
    </script>
</head>
<body>
<h2>API 测试页面</h2>
<table border="0" cellpadding="0" cellspacing="5">
    <tr>
        <td>请求地址</td>
        <td>
            <input type="text" value="http://127.0.0.1:21700" name="txtUrl" id="txtUrl" maxlength="200"/></td>
    </tr>
    <tr>
        <td>请求路径</td>
        <td>
            <select id="txtConller" name="txtConller">

            </select>
    </tr>
    <tr>
        <td>请求行为</td>
        <td>
            <select id="sType" name="sType">
                <option value="POST">Post</option>
                <option value="GET">Get</option>
            </select>

        </td>
    </tr>
    <tr>
        <td>请求参数</td>
        <td>
            <textarea value="" cols="50" rows="10" style="overflow: auto;" name="txtParams" id="txtParams" placeholder=' 例如：{"Id":"001","Name":"张三","Phone":"2014/4/22 13:18:26","EmailAddress":"dulei@51lsh.com"}'></textarea>
        </td>
    </tr>
    <tr>

        <td colspan="2">
            <input type="button" value="提 交" onclick="btnSubmit()"/>
            <input type="button" value="跨域提交" onclick="btnSubmit2()"/>
        </td>
    </tr>
</table>
<span>返回数据：</span>

    <div id="modes">

    </div>
</body>
</html>
